var app = new Vue({
	el: '#app',
	data: {
		url: {
			getContactUs: '/api/ContactUs/GetContactUs',
			confirmContactUs: '/api/ContactUs/ConfirmContactUs'
		},
		infos:{
			user:globalData.userInfo
		},//用户的所有信息
		data: {},
		content: "",
		phone: ""
	},
	mounted: function() {
		var that = this;
		globalData.getTempToken(function(){
			//隐藏loading
			$('.loading').hide()
			that.getContactUs();
			$(function() {
				$('#contacus').bootstrapValidator(contacus_json);
			});
		})
//		
		var test = /(.+@\w+\.\w+)|(1[0-9]{10})/
		console.log(test.test("15207124170"))
		console.log(test.test("asfjlkaj@qq.com"))
		
	},
	methods: {
		getContactUs: function() {
			var that = this;
			var data = {
				pageIndex: 1,
				pageSize: 30
			}
			globalData.ajaxPost(this.url.getContactUs, data, function(res) {
				var d = res.data;
				if(d == null)
					return;
				if(res.suc)
					that.data = d[0];
			})
		},
		csubmit: function() {
			$('#contacus').bootstrapValidator('validate');
			var b = $('#contacus').data("bootstrapValidator").isValid();
			if(b) {
				var data = {
					ContactUsID: this.data.ID,
					Remark: this.content,
					ContactWay: this.phone,
					"ProductID": "1"
				}
				globalData.ajaxPost(this.url.confirmContactUs, data, function(res) {
					if(res.suc) {
						globalData.utils.alert("提交成功!",function(){
							window.location.reload()
						});
						
					}
				});
			}
		}
	}
})

var contacus_json = {
	feedbackIcons: {
		valid: 'glyphicon glyphicon-ok',
		invalid: 'glyphicon glyphicon-remove',
		validating: 'glyphicon glyphicon-refresh'
	},
	fields: {
		content: {
			validators: {
				notEmpty: {
					message: '内容不能为空'
				}
			}
		},
		phone: {
			validators: {
				notEmpty: {
					message: '请输入手机号码/或邮箱'
				},
				stringLength: {
					message: '请输入手机号码/或邮箱'
				},
				regexp: {
					regexp: /(.+@\w+\.\w+)|(^1[0-9]{10}$)/,
					message: '请输入手机号码/或邮箱'
				}
			}
		},
	}
}